package com.ctgu.tengyun.bean.response;

import com.ctgu.tengyun.util.StringUtils;

import static com.ctgu.tengyun.bean.errorcode.ResultConstant.*;

/**
 * Created by liaoweizhi on 2019/7/21.
 */
public class RespGenerator {

    public static final BaseResponse SUCC_BASE_RESP =  generateResponse(SUCC, "OK");
    public static final SimpleResponse SIMPLE_SUCC_RESP = new SimpleResponse(SUCC_BASE_RESP);
    public static final BaseResponse SERVER_INTERNAL_ERR_RESP = generateResponse(SC_INTERNAL_SERVER_ERR_CODE, SC_INTERNAL_SERVER_ERR_DATA);
    public static final BaseResponse LOGGER_OUT_ERR_RESP = generateResponse(LOGOUT_ERR_CODE, LOGOUT_ERR_DATA);
    public static final BaseResponse DUPLICATE_REQUEST_ERR_RESP = generateResponse(DUPLICATE_REQUEST_ERR_CODE, DUPLICATE_REQUEST_ERR_DATA);
    public static final BaseResponse FORBIDDEN_RESP = generateResponse(FORBIDDEN_ERR_CODE, FORBIDDEN_ERR_DATA);
    public static final BaseResponse UNPROCESSABLE_PARAM_RESP = generateResponse(UNPROCESSABLE_ENTITY_ERR_CODE, UNPROCESSABLE_ENTITY_ERR_DATA);
    public static final BaseResponse UNKNOWN_ERROR_RESP = generateResponse(SC_INTERNAL_SERVER_ERR_CODE, SC_INTERNAL_SERVER_ERR_DATA);

    public static BaseResponse generateResponse(Integer code, String message) {
        return generateResponse(code, message, null);
    }

    public static BaseResponse generateResponse(Integer code, String message, String hintMessage) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setErrorCode(code);
        baseResponse.setErrorMessage(StringUtils.notNull(message));
//        baseResponse.setHintMessage(StringUtils.notNull(hintMessage));
        return baseResponse;
    }

    public static BaseResponse getOverThreadHoldErrResp(String errMsg){
        return generateResponse(OVER_THREASHOLD_ERR_CODE, errMsg);
    }

    public static BaseResponse getDuplicateRequestErrResp(String errMsg){
        return generateResponse(DUPLICATE_REQUEST_ERR_CODE, errMsg);
    }

    public static BaseResponse getNotFoundErrResp(String errMsg){
        return generateResponse(NOT_FOUND_ERR_CODE, errMsg);
    }

    public static BaseResponse getUnprocessableErrResp(String errMsg){
        return generateResponse(UNPROCESSABLE_ENTITY_ERR_CODE, errMsg);
    }

    public static BaseResponse getUnauthErrResp(String errMsg){
        return generateResponse(SC_UNAUTHORIZED_ERR_CODE, errMsg);
    }

    public static BaseResponse getPreconditionFailedErrResp(String errMsg){
        return generateResponse(PRECONDITION_FAILED_ERROR_CODE, errMsg);
    }

    public static BaseResponse getExternalSysErrResp(String errMsg){
        return generateResponse(EXTERNAL_SYSTEM_ERR_CODE, errMsg);
    }

    public static BaseResponse getForbiddenErrResp(String errMsg) {
        return generateResponse(FORBIDDEN_ERR_CODE, errMsg);
    }

    public static Object getUnmofiedDataResp(String errMsg) {
        return generateResponse(SYSTEM_BUSY_ERR_CODE, errMsg);
    }

    public static BaseResponse getConcurrentUpdateErrResp(String errMsg) {
        return generateResponse(CONCURRENT_UPDATE_ERR_CODE, errMsg, CONCURRENT_UPDATE_ERR_DATA);
    }

}
